package com.example.demo.api.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.example.demo.api.config.R;
import com.example.demo.api.form.SayHelloForm;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;


@RestController
@RequestMapping("/demo")
public class DemoController {

    @PostMapping("/sayHello")
    @SaCheckLogin
    public R sayHello(@RequestBody @Valid SayHelloForm form){
        return R.ok().put("result","Hello"+form.getName());
    }

    @PostMapping("/login")
    public R login(){
        StpUtil.login(9527);
        String token = StpUtil.getTokenInfo().getTokenValue();
        return R.ok().put("token",token);
    }
}
